<!-- 意见征集反馈意见 -->
<template>
	<view class="page">
		<view style=" background-color: #fff; padding: 20rpx; border-radius: 20rpx; margin-top: 20rpx;">
			<u-form :model="model" :rules="rules" labelPosition="top" ref="feedbackForm" labelWidth="auto" :labelStyle="{
			  fontSize: '14px',
			  color: '#B2B2B2',
			  lineHight: '20px'
			}">
			  <u-form-item label="反馈意见" required prop="feedbackOpinion">
			  	<u--textarea :confirm-type="null" maxlength="500" count required :disabled="timeDisable"
						placeholder="请输入反馈意见"
			  		v-model="model.feedbackOpinion"></u--textarea>
			  </u-form-item>
			</u-form>
		</view>
		<view class="space-x-1 px-1 btn_position"  style="left: 0;">
			<u-button type="primary" :plain="true" text="返回" @click="onReturn"></u-button>
			<u-button type="primary" :disabled="isSubmit" text="保存" @click="onIssue"></u-button>
		</view>
		<view style="height: 100rpx"></view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	import moment from 'moment'
	import {
		messageInfoReadId, // 消息已读
	} from '../../api/index.js'
	import fileList from '../synergy/components/fileList.vue'
	import http from '@/utils/request'
	export default {
		data() {
			return {
				isSubmit: false,
				id: '', // 详情id
				blockingTime: '', // 到期时间
				messageDetail: {}, // 消息详情
				lowerOpinionList:[],//下级签发意见list
				model: {
					feedbackOpinion: ''
				},
				rules: {
					feedbackOpinion: [{ required: true, message: '请输入反馈意见!', trigger: ['blur', 'change'] }],
				}
			}
		},
		components: {
			fileList
		},
		async onLoad(options) {
			this.id = options.id || ''
			this.blockingTime = options.blockingTime || ''
			this.model.feedbackOpinion = options.feedbackOpinion || ''
			// this.detail(this.id)
			// this.getRead() // 获取消息详情已读
		},
		computed: {
		  ...mapState(['userInfo']),
			// 判断当前时间是否大于截止时间，大于则结束填写签发意见
			timeDisable () {
				// 判断当前时间是否已经超过截止时间，如果超过则不能填写反馈意见
					if(this.blockingTime && moment(this.blockingTime).isBefore(moment())){
						return true
					} else {
						return false
					}
			}
		},
		onBackPress(options) {
			// 清空选择通知公告选择的人员
			if (this.$store.state.selectPerson) {
				this.$store.dispatch('actionsSetSelectPerson', '')
			}
		},
		methods: {
			async detail(id) {
				// 获取详情
				if (!id) {
					return false
				} 
				http.get('/api/erp/publishCollect/queryPageById', { id }).then(res => {
					if (res.success) {
						this.messageDetail = res.result.records[0]
					}
				})
			},
			getRead () {
				var params = {
					empId: this.userInfo.empId,
					collectId: this.id
				}
				http.get('/api/erp/publishCollect/read', params).then(res => {
					if (res.success) {
						// 阅读成功
					}
				})
			},
			selectPerson(){
				uni.navigateTo({
					url:'/pages/docManage/selectReceiver'
				})
			},
			
			validateForm() {
				return this.$refs.feedbackForm.validate().then(async () => {
					var that = this
					let nowDateVeri = moment().format('YYYY-MM-DD HH:mm')
					if(moment(this.blockingTime).isBefore(nowDateVeri)){
						uni.showToast({
							title: '已到期无法继续进行意见反馈！',
							icon: 'none'
						})
						return Promise.reject("已到期无法继续进行意见反馈！")
					}
					return Promise.resolve()
				})
			},
			// 反馈
			async onIssue () {
				var that = this
				await this.validateForm()
				this.isSubmit = true
				var params = await {
					empId: this.userInfo.empId,
					id: this.id,
					feedbackOpinion: this.model.feedbackOpinion
				}
				http.post('/api/erp/publishCollect/feedback', params).then(res => {
					if (res.success) {
						this.$refs.uToast.show({
						  message: res.message,
						  type: 'default',
						  complete() {
								uni.navigateBack()
								that.isSubmit = false
						  }
						})
					} else {
						that.isSubmit = false
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				}).catch(err => {
					that.isSubmit = false
				})
			},
			onReturn () {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url('@/assets/inputStyle.scss');
	page{
		// background-color: #FFFFFF;
	}
.page{
	padding: 20rpx;
	.content{
		// text-align: center;
		font-size: 16px;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		color: #171717;
		// margin-top: 30rpx;
	}
	.text{
		margin-top: 32rpx;
		font-size: 14px;
		font-family: PingFangSC-Light, PingFang SC;
		font-weight: 300;
		color: #7F7F7F;
	}
	.time{
		margin: 8rpx 0 32rpx 0;
		font-size: 14px;
		font-family: PingFangSC-Light, PingFang SC;
		font-weight: 300;
		color: #7F7F7F;
	}
	.parase{
		white-space: normal;
	}
}
</style>
